﻿#ifndef IDADIALOGMSG_H
#define IDADIALOGMSG_H

#include <QDialog>
#include <QPointer>
#include <QEventLoop>

#include "IdaPara.h"
#include "API_BaseWidget.h"
//#include "BaseModule/GlobalEnums.h"

namespace Ui { class IdaDialogMsg; };

class IdaTitleBar;
class IdaMainWindow;
class AutoResizingTextBrowser;

//消息对话框类型
enum class EDialogMsg
{
    None = 0,
    Normal,     //正常
    Warning,    //警告
    Error,      //错误
    Question,   //询问
    Custom,     //自定义
};

enum class EDialogMsgResult
{
    None = 0,
    First,      //第一个按钮被点击  //从右往左数
    Second,     //第二个按钮被点击  //第二个按钮为主按钮
    Third,      //第三个按钮被点击
};

class API_BASEWIDGET IdaDialogMsg : public QDialog
{
    Q_OBJECT
        Q_PROPERTY(int DialogType READ getDialogType)
public:
    IdaDialogMsg(QWidget* parent = Q_NULLPTR);
    ~IdaDialogMsg();

    /// @brief 显示对话框
    static EDialogMsgResult showDialog(QWidget* parent, QString content, EDialogMsg dialogType = EDialogMsg::Warning, QString title = QStringLiteral("警告"), QStringList buttonTextList = {});

    /// @brief 事件循环,窗体阻塞
    EDialogMsgResult execDialog(QString content, EDialogMsg dialogType, QString title, QStringList buttonTextList);

    /// @brief 重新设置父窗体
    void resetParent(QWidget* parent);

    /// @brief 获取弹窗类型
    int getDialogType();

private:

    /// @brief 初始化对话框
    void initDialog();

    /// @brief 设置对话框信息
    void setDialogInfo(QString content, EDialogMsg dialogType, QString title, QStringList buttonTextList);

    /// @brief 关闭窗体
    void closeWindow(int status = 0);

    /// @brief 显示窗体
    void showWindow();

    /// @brief 自适应大小
    void perfectSize();

private slots:

    /// @brief 退出窗体阻塞
    void exitExec();

    void on_pushButton_first_clicked();

    void on_pushButton_second_clicked();

    void on_pushButton_third_clicked();
    void slot_closeButtonClick();

private:
    Ui::IdaDialogMsg* ui;
    QPointer<IdaMainWindow> m_windowFrame;    //窗体框架
    QEventLoop m_loop;    //循环事件
    EDialogMsg m_dialogType;     //消息对话框类型
    QStringList m_iconPathList;
    AutoResizingTextBrowser* m_textBrower_content;
};
#endif // IDADIALOGMSG_H
